package com.zhiyou100.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhiyou100.model.User;
import com.zhiyou100.service.UserService;

@Controller
public class LoginController {
	@Autowired
	private UserService userService;
	
	@RequestMapping("/user/login")
	public String login(String username,String password,int verify,Model model) {
		Map<String,String> map = new HashMap<>();
		map.put("username", username);
		map.put("password", password);
		
		// 调用服务层
		User user = userService.login(map);
		System.out.println(">>>>>>>>>>>USER>>>>>>>>>>>"+user);
		System.out.println("<<<<<<<<<<user.real_name<<<<<<<<<<<<"+user.getReal_name());
		model.addAttribute("user", user);
		if(user != null && verify == 7236) {
			return "forward:/index.jsp";
		}
		// 跳转页面
		model.addAttribute("msg", "用户名或密码错误");
		return "forward:/login.jsp";
	}
}
